home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BEERSRC.ZIP / EWD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-31  |  5.0 KB  |  243 lines

  1.  
  2.  
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <stdio.h>
  7. #include <alloc.h>
  8. #include <io.h>
  9. #include <fcntl.h>
  10. #include <sys\stat.h>
  11. #include <dos.h>
  12.  
  13.  
  14. #define   MAXSPRITES        40
  15. #define   MAXWEAPONS        20
  16.  
  17. #include "baller.h"
  18.  
  19. int       nfrnd;
  20. struct armstrc frnd[MAXWEAPONS];
  21.  
  22.  
  23. int save(void)
  24. {
  25.    char      file[80];
  26.    int       filvar;
  27.    int       size, i;
  28.  
  29.    printf("Output file [.WPN]: ");
  30.    fflush(stdin);
  31.    scanf("%s", file);
  32.    strcat(file, ".WPN");
  33.  
  34.    filvar = open(file, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, S_IWRITE);
  35.    if (filvar == -1) return -1;
  36.  
  37.    write(filvar, &nfrnd, 2);
  38.    write(filvar, frnd, nfrnd*sizeof(struct armstrc));
  39.  
  40.    close(filvar);
  41.  
  42.    return 0;
  43. }
  44.  
  45. int load(void)
  46. {
  47.    char      file[80];
  48.    int       filvar;
  49.    int       size, i;
  50.  
  51.    printf("Input file [.WPN]: ");
  52.    fflush(stdin);
  53.    scanf("%s", file);
  54.    strcat(file, ".WPN");
  55.  
  56.    filvar = open(file, O_RDONLY | O_BINARY, S_IREAD);
  57.    if (filvar == -1) { perror("load:"); return -1; }
  58.  
  59.    read(filvar, &nfrnd, 2);
  60.    read(filvar, frnd, nfrnd*sizeof(struct armstrc));
  61.  
  62.    close(filvar);
  63.  
  64.    return 0;
  65. }
  66.  
  67.  
  68. void define(void)
  69. {
  70.  
  71.    if (nfrnd < MAXWEAPONS) {
  72.  
  73.       printf("Define new Weapon:\n\n");
  74.  
  75.       fflush(stdin);
  76.       printf("Enter weapon name >  "); gets(frnd[nfrnd].armname);
  77.       fflush(stdin);
  78.       printf("Gun sprite #      >  "); scanf("%d", &frnd[nfrnd].sprite);
  79.       fflush(stdin);
  80. /*      printf("Release X(-32768) >  "); scanf("%d", &frnd[nfrnd].shotx);
  81.       fflush(stdin);
  82.       printf("Release Y(-32768) >  "); scanf("%d", &frnd[nfrnd].shoty);
  83.       fflush(stdin);
  84. */
  85.       printf("Shot #            >  "); scanf("%d", &frnd[nfrnd].shot);
  86.       fflush(stdin);
  87.       printf("Enter price       >  "); scanf("%d", &frnd[nfrnd].cost);
  88.       fflush(stdin);
  89.       printf("Enter flags [hex] >  "); scanf("%x", &frnd[nfrnd].flags);
  90.       fflush(stdin);
  91.       printf("Gun reload time   >  "); scanf("%d", &frnd[nfrnd].period);
  92.       fflush(stdin);
  93. //      printf("Max power ups     >  "); scanf("%d", &frnd[nfrnd].maxpower);
  94. //      fflush(stdin);
  95.  
  96.       nfrnd++;
  97.  
  98.    }
  99.  
  100. }
  101.  
  102. void change(int n)
  103. {
  104.    char   text[80];
  105.    struct armstrc *ptr;
  106.  
  107.    ptr = &frnd[n];
  108.    printf("Weapon name [%s]: ", ptr->armname);
  109.    fflush(stdin);
  110.    gets(text);
  111.    if (strlen(text) != 0) strcpy(ptr->armname, text);
  112.    printf("Gun sprite [%d]: ", ptr->sprite);
  113.    fflush(stdin);
  114.    gets(text);
  115.    if (strlen(text) != 0) sscanf(text, "%d", &ptr->sprite);
  116. /*   printf("Bullet Release X [%d]: ", ptr->shotx);
  117.    fflush(stdin);
  118.    gets(text);
  119.    if (strlen(text) != 0) sscanf(text, "%d", &ptr->shotx);
  120.    printf("Bullet Release Y [%d]: ", ptr->shoty);
  121.    fflush(stdin);
  122.    gets(text);
  123.    if (strlen(text) != 0) sscanf(text, "%d", &ptr->shoty);
  124. */
  125.    printf("Shot [%d]: ", ptr->shot);
  126.    fflush(stdin);
  127.    gets(text);
  128.    if (strlen(text) != 0) sscanf(text, "%d", &ptr->shot);
  129.    printf("Price [%d]: ", ptr->cost);
  130.    fflush(stdin);
  131.    gets(text);
  132.    if (strlen(text) != 0) sscanf(text, "%d", &ptr->cost);
  133.    printf("Flags [%xh]: ", ptr->flags);
  134.    fflush(stdin);
  135.    gets(text);
  136.    if (strlen(text) != 0) sscanf(text, "%x", &ptr->flags);
  137.    printf("Gun reload time in frames [%d]: ", ptr->period);
  138.    fflush(stdin);
  139.    gets(text);
  140.    if (strlen(text) != 0) sscanf(text, "%d", &ptr->period);
  141. //   printf("Max power ups [%d]: ", ptr->maxpower);
  142. //   fflush(stdin);
  143. //   gets(text);
  144. //   if (strlen(text) != 0) sscanf(text, "%d", &ptr->maxpower);
  145.  
  146.    printf("\n");
  147.  
  148. }
  149.  
  150.  
  151.  
  152. void list(void)
  153. {
  154.    int   i;
  155.  
  156.  
  157.    printf("\n");
  158.    for (i = 0; i < nfrnd; i++) {
  159.       printf("%d. %s\n", i, frnd[i].armname);
  160.    }
  161.  
  162. }
  163.  
  164.  
  165. void delweapon(int n)
  166. {
  167.    int   i;
  168.  
  169.    nfrnd--;
  170.    for (i = n; i < nfrnd; i++) {
  171.       frnd[i] = frnd[i+1];
  172.    }
  173.  
  174. }
  175.  
  176.  
  177.  
  178.  
  179. void main(void)
  180. {
  181.  
  182.    int   choice;
  183.  
  184.    printf("\n\nEXTRA WEAPON DESIGNER !\n");
  185.    printf("[c] copyrigth 1992 by ALPHA-HELIX.\n");
  186.  
  187.  
  188.    nfrnd = 0;
  189.    do {
  190.  
  191.    do {
  192.       printf("\n\n");
  193.       printf("1 - Define new weapon.\n");
  194.       printf("2 - Delete weapon.\n");
  195.       printf("3 - Weapon List.\n");
  196.       printf("4 - Change weapon.\n");
  197.       printf("7 - Save weapons.\n");
  198.       printf("8 - Load weapons.\n");
  199.       printf("9 - Quit EWP.\n");
  200.  
  201.       printf("\nYour choice -> "); choice = getche() - '0';
  202.       printf("\n");
  203.  
  204.       switch (choice) {
  205.      case 1: define();
  206.          break;
  207.  
  208.      case 2: list();
  209.          printf("Enter number of weapon to delete: ");
  210.          fflush(stdin);
  211.          scanf("%d", &choice);
  212.          delweapon(choice);
  213.          break;
  214.  
  215.      case 3: list();
  216.          break;
  217.  
  218.      case 4: list();
  219.          printf("Enter number of weapon to change: ");
  220.          fflush(stdin);
  221.          scanf("%d", &choice);
  222.          change(choice);
  223.          break;
  224.  
  225.      case 8: load();
  226.          break;
  227.  
  228.      case 7: save();
  229.          break;
  230.  
  231.       }
  232.  
  233.    } while (choice != 9);
  234.  
  235.    printf("\n\nQuit without saving (Y/N)? "); choice = getche();
  236.    } while (choice != 'y');
  237.  
  238.    printf("\nThanks for using EWP !\n\n\n\n");
  239.  
  240. }
  241.  
  242.  
  243.